package com.gmail.viktor.yuryev.actions;

import com.gmail.viktor.yuryev.model.MyRemoteServers;
import com.gmail.viktor.yuryev.model.ServerDetails;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Separator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Created by Viktor Yuryev on 4/10/2014.
 */
public class UpdateActionGroup extends ActionGroup {

    /* public UpdateActionGroup() {
         List<ServerDetails> serverList = MyRemoteServers.getInstance().getServerList();
         add(new ConfigureServersAction());
         addSeparator();
         add(new UploadToServerAction(serverList.get(0)));
         add(new UploadToServerAction(serverList.get(0)));
         add(new UploadToServerAction(serverList.get(0)));
         add(new UploadToServerAction(serverList.get(0)));
         add(new UploadToServerAction(serverList.get(0)));

     }
 */
    @Override
    public boolean isPopup() {
        return true;
    }


    public UpdateActionGroup() {
        super("Upload to", true);
    }


    @NotNull
    @Override
    public AnAction[] getChildren(@Nullable AnActionEvent anActionEvent) {
        List<ServerDetails> serverList = MyRemoteServers.getInstance().getServerList();
        int size = serverList.size();
        AnAction[] anActions = new AnAction[size + 2];
        for (int i = 0; i < size; i++) {
            anActions[i] = new UploadToServerAction(serverList.get(i));
        }
        anActions[size] = Separator.getInstance();
        anActions[size + 1] = new ConfigureServersAction();
        return anActions;
    }

}
